import Teacher from "./teacher"
class Class{
    constructor(number){
        this.number=number;        
    }
    getDisplayName(){
        return `Class ${this.number}`;
    }
    registerAssignLeaderListener(teacher){
        this.Teacher=teacher;
    }
    registerJoinListener(teacher){
        this.Teacher=teacher;
    }
    appendMember(Student){
        Student.klass=this;
        if(this.Teacher!=undefined){
            console.log(`I am ${this.Teacher.name}. I know ${Student.name} has joined Class ${this.number}.`);
        }
    }
    isIn(klasses,student){
        if(klasses.indexOf(student.klass)==-1){
            return false;
        }
        else{
            return true;
        }
    }
    assignLeader(Student){
        if(Student.klass==this){
            if(this.number==Student.klass.number){
                this.leader=Student;
                if(this.Teacher!=undefined){
                    console.log(`I am ${this.Teacher.name}. I know ${Student.name} become Leader of Class ${this.number}.`);
                }
            }
        }
        else{
            console.log("It is not one of us.");
        }
    }
}
module.exports=Class;
